package cj.primariaiquest.dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import cj.primariaiquest.ws.xmlConfig.Ticket;

public class TicketEntityManager {

	private transient EntityManagerFactory factory;
	private transient EntityManager entityManager;
	
	 public void TicketManager() {
         factory = Persistence.createEntityManagerFactory("TicketService");
         entityManager = factory.createEntityManager();
 }


	public Ticket getTicket(Long id) {
		return entityManager.find(Ticket.class, id);
	}

	public void addTicket(Ticket ticket) {
		entityManager.getTransaction().begin();
		entityManager.persist(ticket);
		entityManager.getTransaction().commit();
	}

	public void removeTicket(Ticket ticket) {
		entityManager.getTransaction().begin();
		Ticket t = entityManager.find(Ticket.class, ticket.getId());
		entityManager.remove(t);
		entityManager.getTransaction().commit();
	}
	
	

}
